import React, { Component } from "react";

class Demo extends Component {
  state = {};
  static getDerivedStateFromProps(props, state) {
    console.log(props);
    return {
      ...props,
    };
  }
  render() {
    return <h3>Demo组件</h3>;
  }
}
class App extends Component {
  constructor(props) {
    super(props);
    console.log("1、App组件的构造函数");
  }
  state = {
    msg: "牛气冲天",
  };
  static getDerivedStateFromProps(props, state) {
    console.log("2. 执行 getDerivedStateFromProps");
    return {
      ...props,
    };
  }
  render() {
    console.log("3、render函数");
    return (
      <div>
        <Demo msg="牛气冲天"></Demo>
      </div>
    );
  }
  componentDidMount() {
    console.log("4、componentDidMount方法");
  }
}
export default App;
